#include<bits/stdc++.h>
using namespace std;
const int NN=2e5+4;
vector<pair<int,int> >g[NN];
pair<int,int>edge[NN];
bool vis[NN],st[NN],on_circle[NN];
int cnt;
void dfs(int u)
{
	st[u]=true;
	cnt++;
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i].first;
		if(st[v]||vis[g[u][i].second])
			continue;
		dfs(v);
	}
}
stack<int>stk;
bool find_circle(int u,int fa)
{
	if(st[u])
	{
		int x;
		do
		{
			x=stk.top();
			on_circle[x]=true;
			stk.pop();
		}while(x!=u);
		return true;
	}
	st[u]=true;
	stk.push(u);
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i].first;
		if(v==fa)
			continue;
		if(find_circle(v,u))
			return true;
	}
	stk.pop();
	st[u]=false;
	return false;
}
int main()
{
	freopen("graph.in","r",stdin);
	freopen("graph.out","w",stdout);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		edge[i]={u,v};
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	if(n==m)
		find_circle(1,0);
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int k;
		scanf("%d",&k);
		int id[24];
		for(int i=1;i<=k;i++)
			scanf("%d",&id[i]);
		if(n==m)
		{
			if(k>=2)
			{
				puts("NO");
				continue;
			}
			if(on_circle[edge[id[1]].first]&&on_circle[edge[id[1]].second])
				puts("YES");
			else
				puts("NO");
			continue;
		}
		for(int i=1;i<=n;i++)
			st[i]=false;
		for(int i=1;i<=k;i++)
			vis[id[i]]=true;
		cnt=0;
		dfs(1);
		if(cnt==n)
			puts("YES");
		else
			puts("NO");
		for(int i=1;i<=k;i++)
			vis[id[i]]=false;
	}
	return 0;
}
